﻿using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxScheduler;
using DevExpress.Web.ASPxScheduler.Internal;
using DevExpress.XtraScheduler;

public class ScheduleAppointmentFormSaveCallbackCommand : AppointmentFormSaveCallbackCommand 
{	
    public ScheduleAppointmentFormSaveCallbackCommand(ASPxScheduler control)
		: base(control) 
    {
	}
	protected internal new ScheduleAppointmentFormController Controller { get { return (ScheduleAppointmentFormController)base.Controller; } } 

	protected override void AssignControllerValues() 
    {
		var tbSubject = (ASPxTextBox)FindControlByID("tbSubject");
		var tbLocation = (ASPxTextBox)FindControlByID("tbLocation");
		var tbPrice = (ASPxTextBox)FindControlByID("tbPrice");
		var edtStartDate = (ASPxDateEdit)FindControlByID("edtStartDate");
		var edtEndDate = (ASPxDateEdit)FindControlByID("edtEndDate");
        var resource = (ASPxComboBox)FindControlByID("edtResource");
		var memDescription = (ASPxMemo)FindControlByID("memDescription");
		var memContacts = (ASPxMemo)FindControlByID("memContacts");

		Controller.Subject = tbSubject.Text;
		Controller.Location = tbLocation.Text;
	    Controller.ResourceId = resource.SelectedItem.Value;
		//Controller.Description = memDescription.Text;

		Controller.Start = edtStartDate.Date;
		Controller.End = edtEndDate.Date;
		// custom fields 
		//Controller.ContactId = memContacts.Text;
		//Controller.ClientId = Convert.ToDouble(tbPrice.Text);

		var clientStart = FromClientTime(Controller.Start);
		AssignControllerRecurrenceValues(clientStart);
	}
	
    protected override AppointmentFormController CreateAppointmentFormController(Appointment appointment) 
    {
		return new ScheduleAppointmentFormController(Control, appointment);
	}
}
